const Router = require('koa-router')
const router = new Router()

var path = require('path');

router.get('/post', async (ctx, next) => {
    await next()

    await ctx.render('post', {
        title: 'post实例'
    }
    )
});

router.post('/post', async (ctx, next) => {
    console.log(ctx.request.body)
    let first_name = ctx.request.body.first_name
    let last_name = ctx.request.body.last_name
    console.log(first_name)
    console.log(last_name)

    //这里可以加入 针对 first_name,last_name 的处理，例如：查询数据库

    ctx.body = {
        status: 'success',
        first_name: first_name,
        last_name: last_name,
    };

    //这里不要再  next 了，否则，回到首页去了
    //await next()
})

module.exports = router;
